package de.clapp.backend.clublist;

import javax.swing.table.AbstractTableModel;

@SuppressWarnings("serial")
public class ClublistTableModel extends AbstractTableModel
{
    private final String[] columnNames =
    { "clubID", "Name", "Adresse", "Kategorie", "IP" };
    
    private final ClublistModel model;
    
    public ClublistTableModel()
    {
        this.model = ClublistModel.getI();
        this.model.addObserver(this);
    }

    @Override
    public int getColumnCount()
    {
        return columnNames.length;
    }

    @Override
    public int getRowCount()
    {
        return model.getItemCount();
    }

    @Override
    public String getColumnName(int column)
    {
        return columnNames[column];
    }

    @Override
    public boolean isCellEditable(int row, int col)
    {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex)
    {
        switch (columnIndex)
        {
            case 0:
                return model.getItem(rowIndex).getClubID();
            case 1:
                return model.getItem(rowIndex).getName();
            case 2:
                return model.getItem(rowIndex).getAdresse().replace("@", ", ");
            case 3:
                return model.getItem(rowIndex).getKategorie();
            case 4:
                return model.getItem(rowIndex).getIP() + ":" + model.getItem(rowIndex).getPort();
            default:
                return "";
        }
    }
}
